package vn.edu.ptithcm.pim.dao;

import vn.edu.ptithcm.pim.dom.Role;

import java.util.List;

import org.hibernate.LockMode;
import org.hibernate.Transaction;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

@SuppressWarnings({ "rawtypes" })
public class RoleDao extends HibernateDaoSupport {

	public void save(Role role) {
		try {
			Transaction tx = getSession().beginTransaction();
			getHibernateTemplate().save(role);
			tx.commit();
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public void saveOrUpdate(Role role) {
		try {
			Transaction tx = getSession().beginTransaction();
			getHibernateTemplate().saveOrUpdate(role);
			tx.commit();
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public void lock(Role role) {
		try {
			Transaction tx = getSession().beginTransaction();
			getHibernateTemplate().lock(role, LockMode.NONE);
			tx.commit();
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public void delete(Role role) {
		try {
			Transaction tx = getSession().beginTransaction();
			getHibernateTemplate().delete(role);
			tx.commit();
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public Role merge(Role role) {
		try {
			return (Role) getHibernateTemplate().merge(role);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public Role findById(java.lang.Long id) {
		try {
			return (Role) getHibernateTemplate().get(Role.class, id);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public List findByExample(Role role) {
		try {
			return getHibernateTemplate().findByExample("Role", role);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public List getAll() {
		try {
			return getHibernateTemplate().loadAll(Role.class);
		} catch (RuntimeException re) {
			throw re;
		}
	}

}
